<template>
  <div class="marsk" v-if="visable">
    <div class="wrap">
      <div class="tip">
        <slot name="tip">警告</slot>
      </div>
      <div class="content">
        <slot name="content">确定要执行此操作吗</slot>
      </div>
      <div class="button">
        <button class="marsk__button--success" @click="confirm">确定</button>
        <button class="marsk__button--cancel" @click="cancel">取消</button>
      </div>
    </div>
  </div>
</template>

<script>
// 接受一个属性visable，用于控制modal的显示和隐藏
// 接收两个方法，一个叫on-success(确定)，一个叫on-cancel(取消)
export default {
  props: {
    visable: {
      type: Boolean,
      default: () => false,
    },
  },
  methods: {
    cancel() {
      this.$emit("on-cancel");
    },
    confirm() {
      this.$emit("on-confirm");
    },
  },
};
</script>

<style scoped>
.marsk {
  position: fixed;
  background: rgba(0, 0, 0, 0.4);
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  align-items: center;
}
.wrap {
  background-color: white;
  border-radius: 10px;
  width: 350px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}
.tip,
.content,
.button {
  margin: 40px 0;
}
.button {
  display: flex;
  justify-content: space-between;
}
.marsk__button--success {
  outline: none;
  border: 0;
  width: 100px;
  height: 30px;
  background: linear-gradient(90deg, #1596fb, #002dff);
  border-radius: 0.28571429rem;
  display: block;
  color: #fff;
  cursor: pointer;
  margin-right: 20px;
}
.marsk__button--cancel {
  outline: none;
  border: 0;
  width: 100px;
  height: 30px;
  background: linear-gradient(90deg, #fb1515, #c1579e);
  border-radius: 0.28571429rem;
  display: block;
  color: #fff;
  cursor: pointer;
}
h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0;
}
</style>
